package com.nanfang51g3.ckz.http;

import com.nanfang51g3.ckz.exec.api.ServerException;
import com.nanfang51g3.ckz.utils.KLog;

import java.net.SocketTimeoutException;

import rx.Subscriber;

/**
 * 抽象类由子类具体实现数据处理 由#Persenter层实现处理业务逻辑
 */
public abstract class SubscriberInterface<T> extends Subscriber<T> {

    @Override
    public void onError(Throwable e) {

        KLog.i("Evd", "---" + e.toString());
        if (e instanceof java.net.UnknownHostException) {
            _onError("网络连接异常");
            return;
        }
        if (e instanceof java.net.ConnectException) {
            //HTTP没有互联网连接异常
            _onError("服务连接异常");
            return;
        } else if (e instanceof SocketTimeoutException) {
            //HTTP服务器向下异常HTTP一般错误异常
            _onError("网络连接超时");
            return;
        } else if (e instanceof ServerException) {
            _onError("服务器异常");
            return;
        }else if( e instanceof  IllegalStateException){
            _onError("数据解析异常");
            return;
        }
        KLog.i("Evd", "---" + e.getMessage());
        _onError(e.getMessage());
    }

    public abstract void _onError(String msg);

}
